﻿@{
    ViewBag.Title = "PersonSetting";
}
@model WSS.Models.User.USER_USER


<div id="div_content">
    <div class="div_content_header" style="line-height: 1px">
        <ul class="list-inline" style="margin-bottom: 0">
            <li><a linkfor="form1" class="active">基本信息</a></li>
            <li><a linkfor="form2">修改邮箱</a></li>
            <li><a linkfor="form3">修改密码</a></li>
        </ul>
    </div>

    <form class="form-horizontal" role="form" id="form1">

        <div id="div_UserAvatar">
            <img src="@Url.Content("~/Content/images/head/" + Model.USER_PIC)" alt="@(ViewBag.UserName)" class="img-circle" 
                     style=" width:80px; height:80px" id="UserAvatar">
            <input type="hidden"  class="form-control" id="USER_PIC" name="USER_PIC" value="@Model.USER_PIC">
            <div style="margin-top: 10px;">
                <input type="file" name="uploadify" id="uploadify" />
            </div>
        </div>
        <div style="color: #323a45; font-size: 16px; margin: 10px 0 10px;"><span>修改基本信息</span></div>
        <div id="div_UserBasicInfo">
            <div class="form-group">
                <label for="USER_NAME" class="control-label">姓名：</label>
                <div class="div_text">
                    <input type="text"  class="form-control notnull" id="USER_NAME" name="USER_NAME" value="@Model.USER_NAME" >
                </div>
            </div>
            <div class="form-group">
                <label for="USER_GENDER" class="control-label">性别：</label>
                <div class="div_text">
                    <select class="form-control notnull" id="USER_GENDER" name="USER_GENDER">
                        <option  value="1"  @if (Model.USER_GENDER == 1)
                                            {@MvcHtmlString.Create("selected")}>男</option>
                        <option value="2" @if (Model.USER_GENDER == 2)
                                          {@MvcHtmlString.Create("selected")}>女</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="USER_QQ" class="control-label">QQ：</label>
                <div class="div_text">
                    <input type="text"  class="form-control" id="USER_QQ" name="USER_QQ" value="@Model.USER_QQ">
                </div>
            </div>
            <div class="form-group" style="float: left">
                <label for="USER_EMAIL" class="control-label">邮箱：</label>
                <div class="div_text">
                    <input type="text"  class="form-control" id="USER_EMAIL" name="USER_EMAIL"
                       value="@Model.USER_EMAIL"  @if (Model.FLAG_MAIL == 1)
                                                  {
                                                      @Html.Raw(" readonly=\"readonly\"")
                                                  }>
                </div>

            </div>
            <div style="float: left; margin-left: 10px;">
                @if (Model.FLAG_MAIL == 0)
                {
                    <button type="button" class="btn btn-danger btn-sm" onclick="verifyEmail('USER_EMAIL')" style="height: 34px">立即验证</button>
                }
                else
                {
                    <span class="label label-success" style="line-height: 34px">已验证</span>
                }
            </div>
            <div style="clear: both"></div>
            <div class="form-group">
                <label for="USER_PHONE" class="control-label">电话：</label>
                <div class="div_text">
                    <input type="text"  class="form-control" id="USER_PHONE" name="USER_PHONE" value="@Model.USER_PHONE">
                </div>
            </div>
            <div class="form-group">
                <label for="USER_IDCARD" class="control-label">身份证号：</label>
                <div class="div_text">
                    <input type="text"  class="form-control" id="USER_IDCARD" name="USER_IDCARD" value="@Model.USER_IDCARD">
                </div>
            </div>

            <div class="form-group">
                <div style="text-align: center">
                    <input  type="hidden" value="@Model.USER_ID" id="USER_ID"  name="USER_ID"/>
                    <input  type="hidden" value="@Model.HOSP_ID" id="HOSP_ID"  name="HOSP_ID"/>
                    <input  type="hidden" value="@Model.USER_NO" id="USER_NO"  name="USER_NO"/>
                    <button type="button" class="btn btn-default" id="SaveBtn" style="width: 80px; margin-left: 30px">保存</button>
                    <button type="button" class="btn btn-default" id="CancelBtn" style="width: 80px; margin-left: 20px">取消</button>
                </div>
            </div>
        </div>

    </form>

    <form class="form-horizontal" role="form" id="form2" style="display: none">
        <div>
            <div class="form-group" style="float: left">
                <label for="EMAIL" class="control-label">邮箱：</label>
                <div class="div_text">
                    <input type="text"  class="form-control" id="EMAIL" name="EMAIL"
                           value="@Model.USER_EMAIL">
                </div>

            </div>
            <button type="button" class="btn btn-danger btn-sm" onclick="verifyEmail('EMAIL')" style="height: 34px">立即验证</button>
        </div>
    </form>

    <form class="form-horizontal" role="form" id="form3" style="display: none">
        <div style="color: #323a45; font-size: 16px; margin: 10px 0 10px;"><span>修改密码</span></div>
        <div>
            <div class="form-group" style="float: left">
                <label for="password" class="control-label">原密码：</label>
                <div class="div_text">
                    <input type="password" class="form-control notnull" id="password">
                </div>

            </div>
            <div class="form-group" style="float: left">
                <label for="password1" class="control-label">新密码：</label>
                <div class="div_text">
                    <input type="password" class="form-control notnull" id="password1">
                </div>

            </div>
            <div class="form-group" style="float: left">
                <label for="password2" class="control-label">重复密码：</label>
                <div class="div_text">
                    <input type="password" class="form-control notnull" id="password2">
                </div>

            </div>
               <div class="alert alert-danger div_text" style="margin-left: 100px; display: none" id="errorTip"></div>
        </div>

        <div class="form-group">
            <div style="text-align: center">
                <button type="button" class="btn btn-default" id="btn_updatepwd" style="width: 80px; margin-left: 30px" onclick="UpdatePwd()">确认修改</button>
            </div>
        </div>
    </form>

</div>
@section css
{
    <link href="@Url.Content("~/Content/uploadify/uploadify.css")" rel="stylesheet" />
    <style type="text/css">
        body
        {
            padding-top: 0;
        }

        #div_content
        {
            border: 1px solid #ddd;
            border-radius: 4px 4px 0 0;
            box-shadow: none;
            margin: 15px;
            padding: 15px;
        }

        .div_content_header, #div_UserAvatar
        {
            border-bottom: 1px solid #ddd;
            margin-bottom: 10px;
        }


        .form-horizontal .notnull
        {
            background-color: #ffffcc;
        }

        .form-group
        {
            width: 680px;
        }

        .control-label
        {
            width: 100px;
            float: left;
            font-weight: normal;
        }

        .div_text
        {
            float: left;
            margin-left: 15px;
            width: 545px;
        }

        .list-inline li
        {
            cursor: pointer;
        }


            .list-inline li a
            {
                display: block;
                margin: 0 15px;
                padding: 5px 15px;
                color: #8a959e;
                font-size: 16px;
                height: 30px;
                text-decoration: none;
            }

                .list-inline li a.active
                {
                    border-bottom: solid 3px #d84c31 !important;
                    color: #323a45;
                    cursor: default;
                }

                .list-inline li a:hover
                {
                    border-bottom: solid 3px rgba(216, 76, 49, 0.4);
                    color: #323a45;
                }
    </style>
}
@section script
{
    <script type="text/javascript" src="@Url.Content("~/Content/uploadify/jquery.uploadify.min.js")"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            var uploadBtnText = "";
            if ("@Model.USER_PIC" != "default.jpg") {
                uploadBtnText = "修改头像";
            } else {
                uploadBtnText = "上传头像";
            }
            var defaults = {
                swf: '@Url.Content("~/Content/uploadify/uploadify.swf")',
                uploader: '@Url.Content("~/Resource/UploadHandle_UploadImg.ashx")',
                cancelImg: '@Url.Content("~/Content/uploadify/uploadify-cancel.png")',
                height: 30,
                width: 80,
                formData: { uploader: '@Model.USER_ID' },
                buttonText: uploadBtnText,
                fileTypeDesc: '图片文件',
                fileTypeExts: '*.jpg; *.gif; *.jpeg;*.png;*.bmp',
                multi: false,
                fileSizeLimit: '1MB,',
                onUploadSuccess: function(file, data, response) {
                    data = eval("(" + data + ")");
                    if (data.ret == 1) {
                        $("#UserAvatar").attr("src", "@Url.Content("~/Content/images/head/")" + data.ImgName);
                        $("#USER_PIC").val(data.ImgName);

                        $.post("/usercenter/UploadUserAvatar", { imgName: data.ImgName }, function(data) {
                            if (data == "1") {
                                //重新加载用户头像
                                parent.$(".head #headimg").attr("src", $("#UserAvatar").attr("src"));
                            } else {
                                mainfn.msg("头像更新失败");
                            }
                        });
                    } else {
                        mainfn.msg("头像上传失败");
                    }
                },
                onInit: function() {
                    //隐藏上传文件列表
                    $("#uploadify-queue").hide();
                }
            };

            $("#uploadify").uploadify(defaults);
        });
        $(function() {
            $("#SaveBtn").click(function() {
                if (mainfn.checkForm($("#form1"))) {
                    return false;
                }
                $.post("/usercenter/SaveUserInfo", $("#form1").serialize(), function(data) {
                    mainfn.msg(data.msg);
                });
            });
            $(".list-inline li a").click(function() {
                $(".list-inline li a").removeClass("active");
                $(this).addClass("active");
                $("form").hide();
                $("#" + $(this).attr("linkFor")).show();
            });
        });

        /*
                 验证邮箱
                */
        function verifyEmail(id) {
            //验证该用户的该邮箱是否已验证
            if ($("#" + id).val() == '@Model.USER_EMAIL' && '@Model.FLAG_MAIL' == 1) {
                mainfn.msg("当前邮箱已验证！");
            } else {
                $.post("/usercenter/verifyEmail", { email: $("#" + id).val() }, function(data) {
                    if (data == "1") {
                        //验证成功
                        mainfn.msg("验证邮件已发送至邮箱，请查收验证！");
                    } else {
                        mainfn.msg("验证邮件发送失败！");
                    }
                });
            }
        }

/*
         修改密码
        */
        function UpdatePwd() {
            if (mainfn.checkForm($("#form3"))) {
                return false;
            }
            if ($("#password1").val() != $("#password2").val()) {
                $("#errorTip").show();
                $("#errorTip").html("两次输入的密码不一致！");
                return false;
            }
            $.post("/usercenter/CheckOldPwd", { pwd: $("#password").val() }, function(data) {
                if (data == "0") {
                    $("#errorTip").show();
                    $("#errorTip").html("原密码输入有误！");
                    return false;
                } else {
                    $.post("/usercenter/UpdateUerPwd", { pwd: $("#password1").val() }, function(val) {
                        if (val == "1") {
                            $("#errorTip").show();
                            $("#errorTip").html("密码修改成功！");
                        } else {
                            $("#errorTip").show();
                            $("#errorTip").html("数据操作异常！");
                        }
                    });
                }
            });

        }
    </script>

}